import json
from flask import make_response


class JsonResponse:
    def __init__(self, code, data=None, msg=""):
        self.code = code
        self.data = data or {}
        self.msg = msg

    def to_json(self):
        return json.dumps(self.__dict__)

    def to_response(self):
        response = make_response(self.to_json())
        response.headers["Content-Type"] = "application/json; charset=utf-8"
        return response
